<?php

    namespace App\Console\Commands;

    use App\Models\V1\FlowerListModel;
    use Illuminate\Console\Command;
    use Illuminate\Support\Facades\DB;

    class ClearFlower extends Command
    {
        /**
         * The name and signature of the console command.
         *
         * @var string
         */
        protected $signature = 'memberinfo:clear_flower';

        /**
         * The console command description.
         *
         * @var string
         */
        protected $description = '清除memberinfo的flower数据';

        /**
         * Create a new command instance.
         *
         */
        public function __construct()
        {
            parent::__construct();
        }

        /**
         * Execute the console command.
         *
         * @return mixed
         */
        public function handle()
        {
            $data = DB::table('memberinfo')->select('UserID', 'flower_week', 'flower_month', 'flower_last')->get();
            foreach ($data as $k => $v) {
                FlowerListModel::create([
                    'flower_week'  => $v->flower_week,
                    'flower_month' => $v->flower_month,
                    'flower_last'  => $v->flower_last,
                    'user_id'      => $v->UserID
                ]);
            }
            DB::table('memberinfo')->update([
                'flower_week'  => '',
                'flower_month' => '',
                'flower_last'  => ''
            ]);
        }
    }
